﻿
namespace BLPicker
{
    using BLPicker.Factory;
    using BLPicker.OnTheFly;

    /// <summary>
    /// Facade for BLPicker.
    /// </summary>
    public static class BusinessLayerFacade
    {
        /// <summary>
        /// Generate and compile proxy, that resolves concrete business layer by business operation name using dependency container.
        /// </summary>
        /// <typeparam name="TBusinessLayer">Type of business layer.</typeparam>
        /// <param name="businessLayerFactory">Factory for business layer.</param>
        /// <returns>Automatically generated and compiled proxy, that resolves concrete business layer by business operation name using dependency container.</returns>
        public static TBusinessLayer GenerateProxy<TBusinessLayer>(IBusinessLayerFactory<TBusinessLayer> businessLayerFactory)
        {
            IBusinessLayerFactory<TBusinessLayer> factoryProxy = new BusinessLayerFactoryProxy<TBusinessLayer>(businessLayerFactory);
            IBusinessLayerProxyFactory proxyFactory = new OnTheFlyProxyFactory();
            TBusinessLayer proxy = proxyFactory.GetProxy<TBusinessLayer>(factoryProxy);

            return proxy;
        }
    }
}
